package com.qckj.amz.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.enums.BusinessType;
import com.qckj.amz.domain.ProductTempImport;
import com.qckj.amz.service.IProductTempImportService;
import com.qckj.common.utils.poi.ExcelUtil;
import com.qckj.common.core.page.TableDataInfo;

import java.util.Arrays;
import java.util.List;

/**
 * 产品导入Controller
 *
 * @author luchuan
 * @since 1.0 2023-03-28
 */
@RestController
@RequestMapping("/amz/productTempImport")
public class ProductTempImportController extends BaseController {
    @Autowired
    private IProductTempImportService productTempImportService;

    /**
     * 查询产品导入列表
     */
    @PreAuthorize("@ss.hasPermi('amz:productTempImport:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductTempImport productTempImport) {
        Page<ProductTempImport> page = productTempImportService.findProductTempImportPage(productTempImport);
        return getDataTable(page);
    }

    /**
     * 导出产品导入列表
     */
    @PreAuthorize("@ss.hasPermi('amz:productTempImport:export')")
    @Log(title = "产品导入", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProductTempImport productTempImport) {
        List<ProductTempImport> list = productTempImportService.findProductTempImportList(productTempImport);
        ExcelUtil<ProductTempImport> util = new ExcelUtil<>(ProductTempImport.class);
        return util.exportExcel(list, "productTempImport");
    }

    /**
     * 获取产品导入详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:productTempImport:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(productTempImportService.findById(id));
    }

    /**
     * 新增产品导入
     */
    @PreAuthorize("@ss.hasPermi('amz:productTempImport:add')")
    @Log(title = "产品导入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductTempImport productTempImport) {
        productTempImportService.save(productTempImport);
        return AjaxResult.success();
    }

    /**
     * 修改产品导入
     */
    @PreAuthorize("@ss.hasPermi('amz:productTempImport:edit')")
    @Log(title = "产品导入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductTempImport productTempImport) {
        productTempImportService.save(productTempImport);
        return AjaxResult.success();
    }

    /**
     * 删除产品导入
     */
    @PreAuthorize("@ss.hasPermi('amz:productTempImport:remove')")
    @Log(title = "产品导入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        productTempImportService.deleteByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
}
